
package com.kanjian.music.adapter;

import java.util.ArrayList;

import com.kanjian.music.R;
import com.kanjian.music.entity.MenuContent;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MusicMenuListAdapater extends BaseAdapter {

    ArrayList<MenuContent> mDataList;

    Context mContext;

    private LayoutInflater mLayoutInflater;

    public MusicMenuListAdapater(Context context, ArrayList<MenuContent> list) {
        this.mContext = context;
        this.mDataList = list;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mDataList != null ? mDataList.size() : 0;
    }

    @Override
    public MenuContent getItem(int position) {
        return mDataList != null ? mDataList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.item_list_dialog_menu, null);
            holder.mTv_menuLable = (TextView) convertView.findViewById(R.id.item_music_menu_lable);
            holder.mIv_menuIcon = (ImageView) convertView.findViewById(R.id.item_music_menu_icon);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MenuContent menu = getItem(position);
        holder.mIv_menuIcon.setImageResource(menu.mResourceId);
        holder.mTv_menuLable.setText(menu.mLable);
        return convertView;
    }

    static class ViewHolder {
        ImageView mIv_menuIcon;

        TextView mTv_menuLable;
    }

}
